<uieip type="page" value="login" debug="true" timeout="5000"></uieip>
<uieip type="reg" value="console"></uieip>
<!DOCTYPE html>
<html>

<head>
    <uieip type="file" value="inc" src="/yqwin/easyui/include.txt" cache="true" minute="1440"></uieip>
    <uieip type="file" value="css" src="/yqwin/css/yqwin.min" cache="false"></uieip>
    <uieip type="file" value="js" src="/yqwin/src/yqwin.min" cache="false"></uieip>
    <title>Data Edit</title>
</head>

<body style=" margin: 0px;">
    <table style="border-spacing: 0px;">
        <tr>
            <td>
                <table id="tb_m">
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <table id="tb_d">
                </table>
            </td>
        </tr>
    </table>
    <script>
        var dbname="yqbase";

        function form_load() {
            $(window).resize(function () {
                 onresize();
            });
            onresize();

            $("#tb_m").yqDataGrid("loadData");
        }

        function onresize() {
            var w = $(window).width()-2;
            var h = $(window).height();

            $("#tb_m").yqDataGrid("resize", {
                width: w,
                height:h*0.65
            });

            $("#tb_d").yqDataGrid("resize", {
                width: w,
                height:h*0.35-4
            });
        }

        $(function () {
            $.yqDbList({ajaxUrl: "_db.html"}, 
                function (data) {     
                    if (data.error == 0) {
                        dbname=data.rows[0].name;
                        init_m();
                    }else{
                        alert(data.info);
                    }
                });
        });

        function init_m(){
            $("#tb_m").yqDataGrid({
                ajaxUrl: "/_db.html",
                dbname: dbname,
                tbname: "ab_test_m",
                keyId: "sid",

                addWhere: "",
                order: "createtime",

                editMode: 3,
                editModeW: 600,
                editModeH: 450,
                editModeNo: 1,
                loadData: false,
                isPage: true,

                isEdit: true,
                copy: true,
                add: true,
                upp: true,
                del: true,
                isdel: false,
                isdelEdit: false,
                move: false,

                isSimple: true,
                isSeek: true,

                afterBindingTitle: function () {
                    init_d();
                },
                onClickRow: function (index, row) {     //点击行
                    console.log("sssssssssss");
                    if(index==-1){
                        $("#tb_d").yqDataGrid("setBindingValue",null);
                        $("#tb_d").yqDataGrid("clear");
                    } else{
                        $("#tb_d").yqDataGrid("setBindingValue",row["sid"]);
                        $("#tb_d").yqDataGrid("seek");
                    }           
                },

            });
        }

        function init_d(){
            $("#tb_d").yqDataGrid({
                ajaxUrl: "/_db.html",
                dbname: dbname,
                tbname: "ab_test_d",
                keyId: "sid",
                bindingKeyId: "pid",
                bindingValue: null,

                addWhere: "",
                order: "queue",

                editMode: 3,
                editModeW: 600,
                editModeH: 450,
                editModeNo: 1,
                loadData: false,
                isPage: false,

                menuType: 3,
                isEdit: true,
                copy: true,
                add: true,
                upp: true,
                del: true,
                isdel: true,
                isdelEdit: false,
                move: true,

                isSimple: false,
                isSeek: false,
 
                afterBindingTitle: function () {
                    form_load();
                },

                editLinks_r: [{
                    id: "dels",
                    text: "全部删除",
                    iconCls: "icon-remove",
                }],  //右侧附加菜单

                uppActionState: function (s_index, s_row, callback) {     //操作节点状态处理接口
                    var rows = $(this).yqDataGrid("getRows");
                    if(rows.length==0){
                        $(this).yqDataGrid("btnDisable","dels");
                    } else{
                        $(this).yqDataGrid("btnEnable","dels");
                    }
                    callback(true);
                },
                btnAction: function (action, params,callback) {
                    if(action=="dels"){
                        var rows = $(this).yqDataGrid("getRows");
                        for(var i=rows.length-1;i>=0;i--){
                            $(this).yqDataGrid("delRow",i);
                        }
                        callback(false);
                    }else{
                        callback(true);
                    }      
                },
            });
        }
    </script>
</body>

</html>